package syntelos.sx.methods.t;

import syntelos.sx.Headers;

import alto.io.Authentication;
import alto.io.Check;
import alto.io.Code;
import alto.io.Output;
import alto.sys.Reference;

/**
 * List threads, optional request path filter.
 */
public class List 
    extends syntelos.sx.Response
{

    public List(){
        super();
    }


    @Code(Check.Review)
    public void respond(syntelos.sx.Request req)
        throws java.io.IOException,
               java.lang.InterruptedException
    {
        this.setHeader(syntelos.sx.Headers.Method.SXT);
        if (this.isAuthenticated(Authentication.NotApp)){
            Reference[] list = req.list();
            if (null != list){
                Output buf = this.getCreateBuffer().openOutput();
                for (int cc = 0, count = list.length; cc < count; cc++){
                    buf.println(list[cc].toString());
                }
                this.setContentTypeText();
            }
            else {
                this.setStatusNotFound();
            }
        }
        else {
            this.setStatusUnauthorized();
        }
    }

}
